﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using NStore.Domain;
using NStore.Domain.Violations;

namespace NStore.Web.Models
{
    public class ProductFormViewModel
    {
        public Product Product { get; private set; }
        public SelectList Categories { get; private set; }

        public ProductFormViewModel(Product product)
        {
            Product = product;
            Categories = new SelectList(Enum.GetValues(typeof(ProductCategory)));
        }

        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            return Product.GetRuleViolations()
                    .Select(rule => new RuleViolation(rule.ErrorMessage,string.Format("Product.{0}", rule.PropertyName)));
        }
    }
}